import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class UserDeletePage:

    def __init__(self, driver):
        self.driver = driver

    def delete_user_page(self,username):
        # 登陆完成后，进入到主页面，点击用户信息管理
        self.driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        # time.sleep(1)
        # 点击用户信息
        self.driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        # time.sleep(1)
        # 点击删除
        self.driver.find_element(By.XPATH, f'//button[@delete-name="{username}"]').click()
        time.sleep(1)
        # 弹窗中点击确认
        item1 = WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(
            (By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]')))
        item1.click()

    """
        删除成功的信息是  删除该用户成功！,删除失败应该是在同样的位置显示不同的信息，所以如果没有成功就是删除失败，不再新写方法
    """
    def delete_user_success_get_massage(self):
        #获取删除结果信息
        return self.driver.find_element(By.XPATH,'//*[@id="jconfirm-box46118"]/div').text
    # def delete_user_fail_get_message(self):
    #     return self.driver.find_element(By.XPATH,'//*[@id="jconfirm-box46118"]/div')